package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2022/1/10 11:40
 */
@Component
public class HelloListener {

    @KafkaListener(topics = "itcast-topic")
    public void onMessage(String message){
        if (!StringUtils.isEmpty(message)){
            // 反序列化为对象
            User user = JSON.parseObject(message, User.class);
            System.out.println(user);
        }
    }
}
